home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / game / think / Rexoban.lha / Rexoban.rexx < prev   
OS/2 REXX Batch file  |  1999-02-12  |  7KB  |  322 lines

  1. /*----------------------------------------------------------
  2.  
  3. Sokoban game in AREXX!
  4. ---------------------
  5.  
  6.    by Harry
  7.  
  8. EMAIL:
  9.    harry@jooky.cz
  10.  
  11. NOTE:
  12.    see documentation at end of this file to find out more
  13.  
  14. ------------------------------------------------------------
  15. */
  16.  
  17.  
  18.  
  19. CALL Init
  20.  
  21. DO WHILE Level ~> MaxLevel
  22.   CALL Load(Level)
  23.   CALL Play
  24.   IF ToDo = 0 THEN Level = Level + 1
  25.   ELSE BREAK
  26.   END
  27.  
  28. /*-*/
  29.  
  30. CLOSE(win)        /* Just to be nice */
  31. EXIT
  32.  
  33.  
  34.  
  35. /***************/
  36.  
  37. Pixel:            /* Write character on the specified place */
  38.   ARG PixX,PixY,PixC
  39.   Str = Str || '' || PixY+1 || ';' || PixX+1 || 'H' || PixC
  40.   RETURN
  41.  
  42.  
  43. Place:            /* Get the char placed on PlaX, PlaY */
  44.   ARG PlaX,PlaY
  45.   RETURN SUBSTR(P.PlaY,PlaX,1)
  46.  
  47.  
  48. Putit:            /* Put the char PutC on PutX, PutY */
  49.   ARG PutX,PutY,PutC
  50.   P.PutY = OVERLAY(PutC,P.PutY,PutX)
  51.   RETURN
  52.  
  53.  
  54. Play:
  55. /************
  56. This is the inner body of the game
  57. x,y    are coordinates of the player,
  58. dx,dy    is contemplated move
  59. m    is object found on players place
  60. str    is buffer for output
  61. */
  62.  
  63.   DO FOREVER
  64.     Str = ''
  65.     a = ReadCH(win)
  66.  
  67.     IF a = '1B'x THEN BREAK
  68.     IF UPPER(a) = 'N' THEN DO        /* Pressed key for Next level */
  69.       IF Level < MaxLevel THEN ToDo = 0
  70.       END
  71.     IF UPPER(a) = 'P' THEN DO        /* Pressed key for Previous level */
  72.       IF Level > 1 THEN DO
  73.         Level = Level - 2
  74.         ToDo = 0
  75.         RETURN
  76.         END
  77.       END
  78.  
  79.     IF a = '9B'x THEN DO
  80.       in = ReadCH(win)
  81.       xx = x
  82.       yy = y
  83.       dx = (in='43'x)-(in='44'x)
  84.       dy = (in='42'x)-(in='41'x)
  85.       x  = x + dx
  86.       y  = y + dy
  87.  
  88.       m = Place(x,y)
  89.   
  90.       SELECT
  91.         WHEN m = whi THEN NOP
  92.         WHEN m = tar THEN NOP
  93.         WHEN m = box THEN DO        /* Pushing a box */
  94.           px = x + dx
  95.           py = y + dy
  96.           p1 = Place(px,py)        /* Contents of place beyond the box */
  97.           IF p1 = whi THEN DO        /* Can I push a box? */
  98.             CALL Pixel(px,py,Box)
  99.             CALL Pixel(x,y,Whi)
  100.             CALL Putit(px,py,Box)
  101.             CALL Putit(x,y,Whi)
  102.             END
  103.           ELSE IF p1 = Tar THEN DO    /* Pushing a box on target? */
  104.             CALL Pixel(px,py,Ful)
  105.             CALL Pixel(x,y,Whi)
  106.             CALL Putit(px,py,Ful)
  107.             CALL Putit(x,y,Whi)
  108.             ToDo = ToDo - 1        /* We finished another box */
  109.             END
  110.           ELSE DO
  111.             x = xx
  112.             y = yy
  113.             END
  114.           END
  115.         WHEN m = ful THEN DO        /* Pushing a box */
  116.           px = x + dx
  117.           py = y + dy
  118.           p1 = Place(px,py)        /* Contents of place beyond the box */
  119.           IF p1 = whi THEN DO        /* Can I push a box? */
  120.             CALL Pixel(px,py,Box)
  121.             CALL Pixel(x,y,Tar)
  122.             CALL Putit(px,py,Box)
  123.             CALL Putit(x,y,Tar)
  124.             ToDo = ToDo + 1        /* We released one box */
  125.             END
  126.           ELSE IF p1 = Tar THEN DO    /* Pushing a box on another target? */
  127.             CALL Pixel(px,py,Ful)
  128.             CALL Pixel(x,y,Tar)
  129.             CALL Putit(px,py,Ful)
  130.             CALL Putit(x,y,Tar)
  131.             END
  132.           ELSE DO
  133.             x = xx
  134.             y = yy
  135.             END
  136.           END
  137.         OTHERWISE DO
  138.           x = xx
  139.           y = yy
  140.           END
  141.         END
  142.       END
  143.  
  144.     Str = Str || '' || y+1 || ';' || x+1 || 'H'    /* Player */
  145.     WRITECH(win,Str)
  146.     IF ToDo = 0 THEN BREAK
  147.     END
  148.   RETURN
  149.  
  150.  
  151. Load:            /* Load specified level */
  152.   ARG LevNum
  153.  
  154.   L = LevNum
  155.   X = XPos.L        /* Getting measures */
  156.   Y = YPos.L
  157.   D = NLin.L
  158.   ToDo = BoxN.L
  159.  
  160.   IF outopen = 1 THEN CLOSE(win)    /* Close window of old size */
  161.  
  162.   wdx = 8 + FonDX * (LENGTH(Line.L.1) + 2) /* Width - 8 is winborder width */
  163.   wdy = 8 + FonDY * (D + 3)        /* Height- 8 is winborder width */
  164.   wx  = (ScrDX - wdx) % 2        /* Centered X */
  165.   wy  = (ScrDY - wdy) % 2        /* Centered Y */
  166.   wt  = 'Level :' L
  167.  
  168.   IF ~OPEN(win,'RAW:'||wx||'/'||wy||'/'||wdx||'/'||wdy||'/'||wt||'/NOSIZE') THEN EXIT
  169.   outopen = 1
  170.  
  171.   WriteLN(win,'>2mH')    /* This line controls used colors */
  172.  
  173. /* Some alternative color sets are written here
  174.  
  175.   WriteLN(win,'>1mH')
  176.   WriteLN(win,'>2mH')
  177.   WriteLN(win,'>3mH')
  178.   WriteLN(win,'>4mH')
  179.   WriteLN(win,'>5mH')
  180.   WriteLN(win,'>6mH')
  181.   WriteLN(win,'>7mH')
  182.  
  183. */
  184.  
  185.  
  186.   WriteLN(win,'')
  187.   DO i = 1 TO D
  188.     P.i = Line.L.i
  189.     WriteLN(win,' ' || P.i)
  190.     END
  191.  
  192.   WRITECH(win,''||y+1||';'||x+1||'H')    /* Place the player */
  193.  
  194.   RETURN
  195.  
  196.  
  197. Init:
  198.   /** Miscelaneous settings **/
  199.  
  200.   ScrDX = 720            /* Supposed screen sizes (for centering) */
  201.   ScrDY = 400
  202.   FonDX = 8            /* Sizes of used font */
  203.   FonDY = 8
  204.  
  205.   Box   = 'O'            /* Character representing box */
  206.   Whi   = ' '            /* Free place */
  207.   Tar   = '+'            /* Where to place the box */
  208.   Ful   = '0'            /* Target with box on it */
  209.  
  210.   Level = 0            /* Starting level number */
  211.  
  212.  
  213.   /** Level parameters **/
  214.  
  215.   XPos.0 = 16            /* Position X of player */
  216.   XPos.1 = 2
  217.   XPos.2 = 5
  218.   XPos.3 = 11
  219.   XPos.4 = 2
  220.  
  221.   YPos.0 = 8            /* Position Y of player */
  222.   YPos.1 = 3
  223.   YPos.2 = 3
  224.   YPos.3 = 7
  225.   YPos.4 = 3
  226.  
  227.   NLin.0 = 9            /* Number of lines of level */
  228.   NLin.1 = 5
  229.   NLin.2 = 7
  230.   NLin.3 = 11
  231.   NLin.4 = 8
  232.  
  233.   BoxN.0 = 0            /* How much targets to fill */
  234.   BoxN.1 = 3
  235.   BoxN.2 = 6
  236.   BoxN.3 = 4
  237.   BoxN.4 = 0
  238.  
  239.   Line.0.1 = '.--------------------.'
  240.   Line.0.2 = '|ARexx SOKOBAN       |'
  241.   Line.0.3 = '|                    |'
  242.   Line.0.4 = '| N - next level     |'
  243.   Line.0.5 = '| P - previous level |'
  244.   Line.0.6 = '| ESC end game       |'
  245.   Line.0.7 = '|                    |'
  246.   Line.0.8 = '| Press any key      |'
  247.   Line.0.9 = "`--------------------'"
  248.  
  249.   Line.1.1 = '/##########\'
  250.   Line.1.2 = '#         +#'
  251.   Line.1.3 = '#  OOO    +#'
  252.   Line.1.4 = '#         +#'
  253.   Line.1.5 = '\##########/'
  254.  
  255.   Line.2.1 = '.#######.'
  256.   Line.2.2 = '##  +  ##'
  257.   Line.2.3 = '# +O O+ #'
  258.   Line.2.4 = '#  O#O  #'
  259.   Line.2.5 = '# +O O+ #'
  260.   Line.2.6 = '##  +  ##'
  261.   Line.2.7 = ' ####### '
  262.  
  263.   Line.3.1  = '/############'
  264.   Line.3.2  = '#H   ++++   #'
  265.   Line.3.3  = '#   ##   #  #'
  266.   Line.3.4  = '#   ######O##'
  267.   Line.3.5  = '##  (  )   # '
  268.   Line.3.6  = ' # ##### ### '
  269.   Line.3.7  = ' #       # # '
  270.   Line.3.8  = ' # #### O  # '
  271.   Line.3.9  = ' #   O  O# # '
  272.   Line.3.10 = ' #######   # '
  273.   Line.3.11 = '       ##### '
  274.  
  275.   Line.4.1 = '.--------------------.'
  276.   Line.4.2 = '|Congratulations!    |'
  277.   Line.4.3 = '|                    |'
  278.   Line.4.4 = '|You finished all    |'
  279.   Line.4.5 = '|levels.             |'
  280.   Line.4.6 = '|                    |'
  281.   Line.4.7 = '|Press a key to quit.|'
  282.   Line.4.8 = "`--------------------'"
  283.  
  284.   MaxLevel = 4
  285.  
  286.   RETURN
  287.  
  288.  
  289.  
  290. /*
  291.  
  292. General information:
  293. -------------------
  294. Configuration can be made via setting of some variables at
  295. the start of 'Init:' procedure.
  296. Used colors can be changed on line 171.
  297.  
  298.  
  299. Rules of level building:
  300. -----------------------
  301. Characters defining box, target and target with box are defined on the
  302. beginning of the function Init:. Every other character is treated as a
  303. wall.
  304.  
  305. Number of targets to be filled is written in field BoxN.xxx.
  306.  
  307. If you set BoxN to zero, the level will be finished after first
  308. pressing of a key (but ESC or P take their action).
  309.  
  310. The map itself should be made so that player cannot get out of map
  311. since no extra check takes place. Level width will be taken from the
  312. first line, so do not neglect to write all spaces for the level to be
  313. rectangular.
  314.  
  315.  
  316. Implementation:
  317. --------------
  318. The map changes are chained in string buffer Str written
  319. presently at the end of iteration.
  320.  
  321. */
  322.